<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Refresh" content="0;URL=messenger.php">
</head>

<body>
<?php
require_once('php_shared/session_to_db.php');

if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
	session_start();
	
	if( isset($_POST['fid'], $_SESSION['user_id']) )
	{
		if( $_SESSION['user_id'] != '' )
		{
			$db_man = new DbUtils();
			
			if( $db_man->connect() )
			{
				$fuid = $db_man->set_var( $_POST['fid'] );
				$uid = $db_man->set_var( $_SESSION['user_id'] );
				$sql = "DELETE FROM friend WHERE (user_id=$uid AND friend_id=$fuid) OR (user_id=$fuid AND friend_id=$uid)";
				$result = $db_man->query($sql);
				
				if( !$result )
				{
					print "<script language = 'javascript'>alert('An error occured while communicating with database, please try again later.');</script>";
				}else{
					print "<script language = 'javascript'>alert('Successfully removed user from your friend list.');</script>";
				}
				
				$db_man->close();
			}
		}
	}
}
?>
</body>
</html>